﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserAdd : System.Web.UI.Page
{
    LogicLayer logic = new LogicLayer();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Button1.Attributes["onclick"] = "return alert('插入成功!')";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string eid, name, deptid="", email, mobile, salary;
        string sex, status;
        string ondate, offdate;
        string place, dname;

        eid = TextBox1.Text.Trim().ToString();
        name = TextBox2.Text.Trim().ToString();
        email = TextBox3.Text.Trim().ToString();
        mobile = TextBox4.Text.Trim().ToString();
        salary = TextBox5.Text.Trim().ToString();

        if (RadioButtonList1.Text.Trim().ToString() == "帅哥")
            sex = "男";
        else
            sex = "女";

        status = RadioButtonList2.Text.Trim().ToString();

        ondate = DropDownList6.Text + "-" + DropDownList7.Text + "-" + DropDownList8.Text;
        offdate = DropDownList1.Text + "-" + DropDownList2.Text + "-" + DropDownList3.Text;

        place = DropDownList4.Text;
        dname = DropDownList5.Text;

        if (place == "北京" && dname == "网络搜索部")
            deptid = "1001";
        else if (place == "北京" && dname == "软件开发部")
            deptid = "1002";
        else if (place == "北京" && dname == "人力资源部")
            deptid = "1003";
        else if (place == "北京" && dname == "系统设计部")
            deptid = "1004";
        else if (place == "北京" && dname == "产品研发部")
            deptid = "1005";
        else if (place == "北京" && dname == "市场部")
            deptid = "1006";

        else if (place == "上海" && dname == "网络搜索部")
            deptid = "2001";
        else if (place == "上海" && dname == "系统设计部")
            deptid = "2002";
        else if (place == "上海" && dname == "产品研发部")
            deptid = "2003";
        else if (place == "上海" && dname == "市场部")
            deptid = "2004";

        else if (place == "广州" && dname == "软件开发部")
            deptid = "3001";
        else if (place == "广州" && dname == "产品研发部")
            deptid = "3002";
        else if (place == "广州" && dname == "系统设计部")
            deptid = "3003";
        else if (place == "广州" && dname == "测试部")
            deptid = "3004";


        string sqlstring = "insert into employee(EmployID,EmployName," +
            "DeptID,Email,Mobile,Sex,Status,OnboardDate,OffboardDate,Salary)" +
            " values(" + eid + ",'" + name + "','" +deptid+"','"+ email + "','" + mobile + "','" + sex +
                "','" + status + "','" + ondate + "','" + offdate + "','" + salary +
                "')";

        if (place == "北京")
            logic.ExcuteSQLStatement_BJ(sqlstring);
        else if (place == "上海")
            logic.ExcuteSQLStatement_SH(sqlstring);
        else
            logic.ExcuteSQLStatement_GZ(sqlstring);

        
        Response.Redirect("UserManager.aspx");

    }
    
}
